package com.sea.human.controller;

import com.codecrane.core.Constants;
import com.codecrane.core.power.entity.PowerGroup;
import com.codecrane.core.power.entity.PowerUser;
import com.codecrane.core.power.service.PowerGroupService;
import com.codecrane.core.power.service.PowerUserService;
import com.codecrane.core.web.Ajax;
import com.codecrane.core.web.AjaxTableReturn;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sea.human.entity.Performance;
import com.sea.human.entity.PerformanceRecord;
import com.sea.human.service.PerformanceRecordService;
import com.sea.human.service.PerformanceService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 *  控制器
 * @author 陈鸿飞
 *  <br/>
 *  <br/>
 */
@Controller
@RequestMapping("/sea/human/performanceRecord")
public class PerformanceRecordController {

    @Autowired
    private PerformanceRecordService performanceRecordService;

    /**
     * 管理主页面
     *
     * @param model
     * @return
     */
    @RequestMapping("/main")
    public String main(Model model,@RequestParam("performanceId")Integer performanceId) {
        model.addAttribute("performanceId",performanceId);
        return "/sea/human/performanceRecord/main";
    }


    /**
     * 分页条件查询
     *
     * @param pagesize
     * @param start
     * @return
     */
    @ResponseBody
    @RequestMapping("/findByCnd")
    public AjaxTableReturn findByCnd(@RequestParam(value = "limit", defaultValue = "10") int pagesize,
                                     @RequestParam(value = "offset", defaultValue = "0") int start,
                                     @RequestParam("performanceId")Integer performanceId) {
        start = start > 0 ? start / pagesize + 1 : 1;
        PageHelper.startPage(start, pagesize);
        List<PerformanceRecord> performanceList = performanceRecordService.findByCnd(performanceId);
        PageInfo<PerformanceRecord> page = new PageInfo<>(performanceList);
        return Ajax.tableDataOk(page.getTotal(), page.getList());
    }



}
